package mailsender

import grails.gsp.PageRenderer

class AwsEmailService {

    PageRenderer groovyPageRenderer

    def sendMail(Map params) {

        log.info('Mail Request Received by AWS Service')
        log.debug(params?.dump())

        try {
            String htmlBody = groovyPageRenderer.render(template:params.template, model: params.model)
            //call to AWS Mail Plugin
            def mailId = sesMail {
                to params.user.username
                subject params.subject
                html htmlBody
            }

            log.info("Mail Sent.  ID: ${mailId}")
        } catch(e) {
            log.error('Sending Mail Failed')
            log.error(e.message)
            e.stackTrace.each{log.error(it)}
        }
    }
}
